#include "MainService.h"
#include <cyber/MidNightMap.h>
#include <cyber/LandMarks.h>
#include <amk3/EarthWrapper.h>
#include <cyber/NightBuildings.h>
#include <amk3/BaseScene.h>
#include "QMLInterface.h"

MainService::MainService()
{
}


MainService::~MainService()
{
}

MainService* MainService::instance()
{
	static MainService ms;
	return &ms;
}

void MainService::setMidNightStyle(bool b)
{
	if (b){
		if (!_midnightMap){
			_midnightMap = new MidNightMap();
			_midnightMap->setMapNode(EarthWrapper::instance()->getMapNode());
		}
		_midnightMap->setEnable(b);
	}
	else{
		if (_midnightMap){
			_midnightMap->close();
			delete _midnightMap;
			_midnightMap = 0;
		}
	}
}

void MainService::showLandMarks()
{

    LandMarks* scene = dynamic_cast<LandMarks*>(_currentScene.get());
    if (scene) {
        _currentScene->close();
        //delete _currentScene;
        _currentScene = 0;
    }
    else {
        if (_currentScene) {
            _currentScene->close();
            //delete _currentScene;
            _currentScene = 0;
        }
        scene = new LandMarks();
        scene->addLevel(4000000, 13000000, false);
        scene->addLevel(1300000, 4000000, false);
        scene->addLevel(60000, 1300000, true);
        scene->addLevel(0, 60000, true);
        //source->addLevel(0,200000);
        scene->setBounds(osgEarth::Bounds(-180, -90, 180, 90));
        scene->open();
        _currentScene = scene;
    }

}

void MainService::showMidBuildings()
{
	NightBuildings* nb = new NightBuildings();
	nb->setShpFilePath("../user_data/cyber/shp/zz.shp");
	nb->open();
}
#include <cyber/HightlightLine.h>
void MainService::showCyberThreat()
{
	HightlightLineScene* scene = dynamic_cast<HightlightLineScene*>(_currentScene.get());
	if (scene){
		_currentScene->close();
		//delete _currentScene;
		_currentScene = 0;
		emit QMLInterface::instance()->signalShowThreatWidget(false);
	}
	else{
		if (_currentScene){
			_currentScene->close();
			//delete _currentScene;
			_currentScene = 0;
		}
		scene = new HightlightLineScene();
		scene->loadData();
		scene->open();
		_currentScene = scene;
		emit QMLInterface::instance()->signalShowThreatWidget(true);
	}
	
}

void MainService::setCyberThreatType(int i)
{
	HightlightLineScene* scene = dynamic_cast<HightlightLineScene*>(_currentScene.get());
	if (scene) {
		scene->setType(i);
	}
}

void MainService::setCyberThreatFilter(QString str)
{
	HightlightLineScene* scene = dynamic_cast<HightlightLineScene*>(_currentScene.get());
	if (!scene) return;

	if (str.length() < 1) {
		scene->setCity("");
		scene->setType(-1);
	}

	QStringList list = str.split(":");
	if (list.size() < 1) return;
	QString f1 = list.at(0);
	if (f1 == "city" && list.length() > 1) {
		scene->setCity(list.at(1));
	}
}
